package cn.com.chifeng.mygreedao;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.student.dao.DaoMaster;
import com.student.entity.Student;

import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_add;
    //查选全部
    private Button btn_load_all;
    //链接工具类
    private CommonUtils dbUtils;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dbUtils = new CommonUtils(this);
        btn_add = (Button) findViewById(R.id.btn_add);
        btn_load_all = (Button) findViewById(R.id.btn_load_all);
        btn_add.setOnClickListener(this);
        btn_load_all.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_add:
                Student student = new Student();
//                student.setId((long) 2);
                student.setName("lgl");
                student.setAge(18);
                student.setAddress("北京");
                boolean flag = dbUtils.insertStudent(student);
                Log.e("===========","nihaola"+flag);
                break;
            case R.id.btn_load_all:
                List<Student> lists = dbUtils.listAll();
                Log.e("===========", lists.toString());
                break;
        }
    }
}
